#include "PreComplied.h"
#include "Test.h"
#include "Script.h"

int MyMax(int a, int b)
{
	LuaInfo("MyMax is called with a = %d, b = %d\n", a, b);
	return a > b ? a : b;
}

const char* Print(const char* str)
{
	LuaInfo("Print is called with str = %s\n", str);
	return "Str return by C++";
}

class T
{
public:
	T()
	{
		static int i = 0;
		++i;
	}
	void Test()
	{
		LuaInfo("T::Test() is called\n");
	}
	int Get()
	{
		LuaInfo("T::Get() is called m_var = %d\n", m_var);
		return m_var;
	}
	void Set(int var)
	{
		LuaInfo("T::Set() is called var = %d\n", var);
		m_var = var;
	}
	const char* Str()
	{
		LuaInfo("T::Str() is called\n");
		return "Str return from T::Str";
	}
	static int SAdd(int a, int b)
	{
		LuaInfo("T::SAdd is called a = %d, b = %d\n", a, b);
		return a + b;
	}
public:
	int m_var;
};

class A
{
public:
	int TA(int i)
	{
		LuaInfo("A::TA is called with i = %d\n", i);
		return ++i;
	}
	int Get()
	{
		return m_var;
	}
	int m_var;
};

class B
{
public:
	int TB(int i)
	{
		LuaInfo("B::TB is called with i = %d\n", i);
		return ++i;
	}
};

class C:public A, public B
{
public:
	const char* TC(int i)
	{
		LuaInfo("C::TC is called with i = %d\n", i);
		return "Str return from C::TC";
	}
};

class D:public C
{
public:
	int TD(int i)
	{
		LuaInfo("D::TD is called with i = %d\n", i);
		return ++i;
	}
	void Copy(A* ptr)
	{
		//ptr->TA();
	}
};

void TestFreeFun()
{
	g_pScript->RFreeFun("MyMax", MyMax);
	g_pScript->RFreeFun("Print", Print);
}

void TestMemFun()
{
	g_pScript->RClass<T>("T");
	g_pScript->RMemberFun<T>("Test", &T::Test);
	g_pScript->RMemberFun<T>("Get", &T::Get);
	g_pScript->RMemberFun<T>("Set", &T::Set);
	g_pScript->RMemberFun<T>("Str", &T::Str);
	g_pScript->RMemberFun<T>("Add", &T::SAdd);
}

void TestInhert()
{
	lua_State* L = g_pScript->GetLuaState();
	g_pScript->RClass<A>("A");
	g_pScript->RMemberFun<A>("TA", &A::TA);
	g_pScript->RMemberFun<A>("Get", &A::Get);

	g_pScript->RClass<B>("B");
	g_pScript->RMemberFun<B>("TB", &B::TB);

	g_pScript->RClass<C>("C");
	g_pScript->RMemberFun<C>("TC", &C::TC);
	g_pScript->RClassInh<C, A>();
	g_pScript->RClassInh<C, B>();

	g_pScript->RClass<D>("D");
	g_pScript->RMemberFun<D>("TD", &D::TD);
	g_pScript->RClassInh<D, C>();

}

